package com.qi.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qi.mapper.ActivityMapper;
import com.qi.pojo.entity.Activity;
import com.qi.pojo.entity.User;
import com.qi.services.IActivityService;
import com.qi.services.IClubService;
import com.qi.services.IUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements IActivityService {

    @Resource
    private IUserService userService;

    @Resource
    private IClubService clubService;

    @Override
    public IPage<Activity> nativeList(Long current, Long size) {
        IPage<Activity> activityPage = new Page<>(current, size);
        User curUser = userService.getCurUserInfo();
        LambdaQueryWrapper<Activity> queryWrapper = new LambdaQueryWrapper<Activity>()
                .eq(Activity::getClubId, curUser.getClubId());
        activityPage = this.page(activityPage, queryWrapper);
        for (Activity record : activityPage.getRecords()) {
            record.setMasterName(userService.getById(record.getMasterId()).getName());
            record.setClubName(clubService.getById(record.getClubId()).getName());
        }
        return activityPage;
    }

    @Override
    public IPage<Activity> getList(Long current, Long size) {
        IPage<Activity> activityPage = new Page<>(current, size);
        activityPage = this.page(activityPage);
        for (Activity record : activityPage.getRecords()) {
            record.setMasterName(userService.getById(record.getMasterId()).getName());
            record.setClubName(clubService.getById(record.getClubId()).getName());
        }
        return activityPage;
    }
}
